package model

import (
	"fmt"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
	"time"
)

type User2 struct {
	ID        uint       `gorm:"primary_key" json:"id"`
	Email     string     `json:"email"`
	Name      string     `json:"name"`
	Del       int        `json:"del"`
	CreatedAt time.Time  `json:"createTime"`
	UpdateAt  *time.Time `sql:"index" json:"updateTime"`
}

var defDB *gorm.DB

func init() {

	host := "www.dmyily2.cn"
	port := 3306
	username := "ycc-im"
	password := "ycc-im123456"
	Dbname := "ycc-im"

	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local", username, password, host, port, Dbname)
	db, err := gorm.Open("mysql", dsn)
	if err != nil {
		panic(err)
	}
	defDB = db

	db.AutoMigrate(&User2{})
}

func GetDB() *gorm.DB {
	return defDB
}
